package org.projecteboot.reptile.common.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.projecteboot.reptile.common.entity.ReptileLog;
import org.projecteboot.reptile.common.mapper.ReptileLogMapper;
import org.projecteboot.reptile.common.service.ReptileLogService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 爬虫日志 服务实现类
 * </p>
 *
 * @author LuoQiang
 * @since 2019-08-30
 */
@Service
@Slf4j
public class ReptileLogServiceImpl extends ServiceImpl<ReptileLogMapper, ReptileLog> implements ReptileLogService {

    @Override
    public void warn(String content, Object... obj) {

        if (obj != null && obj.length > 0) {
            for (int i = 0; i < obj.length; i++) {
                if (content.indexOf("{}") > -1) {
                    content = content.replace("{}", obj.toString());
                }
                break;
            }
        }
        ReptileLog reptileLog = new ReptileLog();
        reptileLog.setContent(content);
        reptileLog.setLevel("WARN");
        save(reptileLog);
        log.warn("数据库日志记录:{}", reptileLog);
    }
}
